import org.junit.jupiter.api.Test

/**
 * @Author ZhouHang
 * @Date 24/6/9 周日
 */
class LearnTest {
    @Test fun `Also Test`() {
        val numbers = mutableListOf("one", "two", "three")
        numbers
            .also { println("The list elements before adding new one: $it") }
//            .add("four")
    }

    @Test fun `Difference Between init and construction`() {
        // init 是必须执行的块
        Person("Zhou", "Hang")
    }

    @Test fun `Set Test`() {
        val s = mutableSetOf<String>()
        val l = mutableListOf<String>()
        l.add("123")
        l.add("123")
        l.add("123")
        var f = s.addAll(l)
        println("$f: $s")

        val l2 = listOf("123", "456")
        f = s.addAll(l2)
        println("$f: $s")
    }
}


class Person(firstName: String, lastName: String) {
    private val fullName: String = "$firstName $lastName".trim()
        .also { println("Initializing full name: $it") }

    init {
        println("You're $fullName")
    }

    private val initials =  "${firstName.firstOrEmpty()}${lastName.firstOrEmpty()}".trim()
        .also { println("Initializing initials: $it") }

    init {
        println("You're initials are $initials")
    }

    constructor(lastName: String): this("", lastName) {
        println("I'm secondary")
    }

    private fun String.firstOrEmpty(): Char = firstOrNull()?.uppercaseChar() ?: ' '
}